import pygame
class Ship:
    def __init__(self,ai_game):

        #初始化飞船并初始化其位置
        self.screen=ai_game.screen
        self.settings=ai_game.settings
        self.screen_rect=ai_game.screen.get_rect()
        #加载飞船并得到其外接矩形
        self.image=pygame.image.load('images/ship.bmp')
        self.rect=self.image.get_rect()
        #每艘飞船都在底部中央
        self.rect.midbottom=self.screen_rect.midbottom

        #在飞船的属性x中存储一个浮点数
        self.x=float(self.rect.x)

        #移动标记，飞船一开始不动
        self.moving_right=False
        self.moving_left=False
    def update(self):
        if self.moving_right and self.rect.right<self.screen_rect.right:
            self.x+=self.settings.ship_speed
        if self.moving_left and self.rect.left>0:
            self.x-=self.settings.ship_speed
        self.rect.x=self.x
        

    #在指定位置绘制飞船
    def blitme(self):
        self.screen.blit(self.image,self.rect)